//
//  EggAnimationView.m
//  jingjing2.0
//
//  Created by apple on 16/5/24.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "EggAnimationView.h"
@implementation EggAnimationView
-(id)initWithFrame:(CGRect)frame
{
    if (self=[super initWithFrame:frame]) {
        self.layer.cornerRadius=10;
        self.clipsToBounds=YES;
        self.backgroundColor=[UIColor whiteColor];
        [self setUpAnimationWithFrame:frame];
        [self setUpProgressView];
        [self setUpLabel];
    }
    return self;
}
-(void)setUpAnimationWithFrame:(CGRect)rect
{
   _animationEgg=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"egg1.jpg"]];
    CGFloat heigth=rect.size.height/2.0-10;
    CGFloat X=(rect.size.width-(heigth-20))/2.0;
    _animationEgg.frame=CGRectMake(X, 20, heigth-20, heigth);

    [self addSubview:_animationEgg];
    
    NSMutableArray *arr=[NSMutableArray array];
    for (int i=0; i<6; i++) {
        NSString *str=[NSString stringWithFormat:@"egg%d.jpg",i+1];
        UIImage *image=[UIImage imageNamed:str];
        [arr addObject:image];
    }
    _animationEgg.animationImages=arr;
    _animationEgg.animationDuration=0.5;
    _animationEgg.animationRepeatCount=0;
}
-(void)setUpProgressView
{
    UIImage * backgroundImage = [[UIImage imageNamed:@"progress-bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 10, 0, 10)];
    UIImage * foregroundImage = [[UIImage imageNamed:@"progress_bar"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 10, 0, 10)];
    _progressBarView = [[MCProgressBarView alloc] initWithFrame:CGRectMake(10, _animationEgg.frame.origin.y+_animationEgg.frame.size.height+20, self.frame.size.width-20, 20) backgroundImage:backgroundImage
      foregroundImage:foregroundImage];
    [self addSubview:_progressBarView];
    _progressBarView.progress = 0;
}
-(void)setUpLabel
{
    for (int i=0; i<2; i++) {
        UILabel *title=[[UILabel alloc]initWithFrame:CGRectMake(10, i*(20+5)+_progressBarView.frame.origin.y+20+20, self.frame.size.width-20, 40)];
        title.font=[UIFont systemFontOfSize:13];
        title.textColor=[UIColor blackColor];
        title.textAlignment=NSTextAlignmentCenter;
        if (i==0) {
            title.text=@"一大波优惠正在向您奔来";
        }else
        {
            title.text=@"请您耐心等待一下下～";
        }
        [self addSubview:title];
    }
    
}
@end
